package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.Objects;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.FlowerInfoRemarkMapper;
import com.ruoyi.system.domain.FlowerInfoRemark;
import com.ruoyi.system.service.IFlowerInfoRemarkService;

import javax.annotation.Resource;

/**
 * 花卉信息评论Service业务层处理
 *
 * @author lwb
 * @date 2024-12-26
 */
@Service
public class FlowerInfoRemarkServiceImpl implements IFlowerInfoRemarkService {
    @Resource
    private FlowerInfoRemarkMapper flowerInfoRemarkMapper;

    @Resource
    private ISysUserService userService;

    /**
     * 查询花卉信息评论
     *
     * @param id 花卉信息评论主键
     * @return 花卉信息评论
     */
    @Override
    public FlowerInfoRemark selectFlowerInfoRemarkById(Long id) {
        return flowerInfoRemarkMapper.selectFlowerInfoRemarkById(id);
    }

    /**
     * 查询花卉信息评论列表
     *
     * @param flowerInfoRemark 花卉信息评论
     * @return 花卉信息评论
     */
    @Override
    public List<FlowerInfoRemark> selectFlowerInfoRemarkList(FlowerInfoRemark flowerInfoRemark) {
        return flowerInfoRemarkMapper.selectFlowerInfoRemarkList(flowerInfoRemark);
    }

    /**
     * 新增花卉信息评论
     *
     * @param flowerInfoRemark 花卉信息评论
     * @return 结果
     */
    @Override
    public int insertFlowerInfoRemark(FlowerInfoRemark flowerInfoRemark) {
        flowerInfoRemark.setCreateTime(DateUtils.getNowDate());

        SysUser user = userService.selectUserById(SecurityUtils.getUserId());
        if (Objects.nonNull(user)) {
            flowerInfoRemark.setUserId(user.getUserId());
            flowerInfoRemark.setUserName(user.getNickName());
        }

        return flowerInfoRemarkMapper.insertFlowerInfoRemark(flowerInfoRemark);
    }

    /**
     * 修改花卉信息评论
     *
     * @param flowerInfoRemark 花卉信息评论
     * @return 结果
     */
    @Override
    public int updateFlowerInfoRemark(FlowerInfoRemark flowerInfoRemark) {
        flowerInfoRemark.setUpdateTime(DateUtils.getNowDate());
        return flowerInfoRemarkMapper.updateFlowerInfoRemark(flowerInfoRemark);
    }

    /**
     * 批量删除花卉信息评论
     *
     * @param ids 需要删除的花卉信息评论主键
     * @return 结果
     */
    @Override
    public int deleteFlowerInfoRemarkByIds(Long[] ids) {
        return flowerInfoRemarkMapper.deleteFlowerInfoRemarkByIds(ids);
    }

    /**
     * 删除花卉信息评论信息
     *
     * @param id 花卉信息评论主键
     * @return 结果
     */
    @Override
    public int deleteFlowerInfoRemarkById(Long id) {
        return flowerInfoRemarkMapper.deleteFlowerInfoRemarkById(id);
    }
}
